package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.LabelParam;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.LabelParamService;

/**
 * to achieve the label to add, delete, update and query
 * @author wj
 * @date 2020/4/8
 *
 */
@Controller
@RequestMapping(value = "/labelParam")
public class LabelParamController {
	
	@Autowired
	private LabelParamService labelParamService;
	
	@RequestMapping(value = "/operateByLabelParam")
	public @ResponseBody ResultBean operateByLabelParam(@RequestBody LabelParam labelParam) {
		ResultBean resultBean = new ResultBean(true,' ');
		// Judge to add
		if (labelParam.getModificationFlag()== IModificationFlags.NEW) {
			return labelParamService.save(labelParam);
		// Judge to update
		} else if (labelParam.getModificationFlag() == IModificationFlags.MODIFIED) {
			return labelParamService.update(labelParam);
		// Judge to delete
		} else if (labelParam.getModificationFlag() == IModificationFlags.DELETED) {
			return labelParamService.delete(labelParam);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/deleteBatch")
	public @ResponseBody ResultBean deleteBatch(@RequestBody List<LabelParam> labelParamList) {
		return labelParamService.deleteBatch(labelParamList);
	}


}
